import openpyxl

from Python.test.Utils.DB_Utils import DBUtils
from read_excel import ReadExcel
from write_excel import generate_user_info_data

if __name__ == '__main__':
    # 调用方法生成2000条模拟数据
    data_list = generate_user_info_data()

    # 批量插入数据
    workbook = openpyxl.Workbook('user_info.xlsx')
    worksheet = workbook.create_sheet('user')
    for item in data_list:
        worksheet.append(item)
    workbook.save('user_info.xlsx')

    #  读取Excel文件中的数据
    data = ReadExcel.read_excel('user_info.xlsx', 'user')

    db = DBUtils(
        host="localhost",
        user="root",
        passwd="root",
        database="hrjt",
    )

    for item in data:
        sql = f"insert into user_info values{tuple(item)};"
        db.sql_cru(sql)